package com.example.demo2.controller;

import com.example.demo2.Util.FileUtil;
import com.example.demo2.generator.entity.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
@Api(value = "上传图片Controller",tags ="上传图片接口" )
@Controller
@RequestMapping(value = "/onload",method = RequestMethod.POST)
public class OnloadController {
    @Autowired
    private FileUtil fileUtil;
    @ApiOperation("上传图片")
    @RequestMapping("/img")
    @ResponseBody
    public R uploadImg(@ApiParam("图片") MultipartFile file) throws IOException {
        String url= fileUtil.save(file);
        System.out.println(url);
        return url!=null?R.ok(url):R.fail("上传图片失败");
    }
}
